package com.biboheart.demos.random.executor;

import org.springframework.stereotype.Component;
import java.util.Random;

@Component
public class Phone implements Generator {
    @Override
    public String generate() {
        return generatePhone();
    }

    private String generatePhone() {
        // 手机号码开头的第二位数字
        String[] secondDigits = {"3", "4", "5", "6", "7", "8", "9"};
        Random random = new Random();
        // 随机选择第二位数字
        String secondDigit = secondDigits[random.nextInt(secondDigits.length)];
        StringBuilder phoneNumber = new StringBuilder("1" + secondDigit);
        // 随机生成后面 9 位数字
        for (int i = 0; i < 9; i++) {
            phoneNumber.append(random.nextInt(10));
        }
        return phoneNumber.toString();
    }
}
